package org.moonlight.jvm.natives.java.lang.clazz;

import org.moonlight.jvm.natives.AbstractNativeMethod;
import org.moonlight.jvm.rtda.exclusive.Frame;
import org.moonlight.jvm.rtda.share.Object;
import org.moonlight.jvm.rtda.share.heap.Class;
import org.moonlight.jvm.rtda.share.methodarea.StringPool;

/**
 * java.lang.Class native String getName0()
 *
 * @author Moonlight
 * @createTime 2023/9/20 18:26
 **/
public class GetName0 extends AbstractNativeMethod {

    public GetName0() {
        super(JAVA_LANG_CLASS, "getName0", "()Ljava/lang/String;");
    }

    @Override
    public void nativeMethod(Frame frame) {
        Object that = frame.getLocalVars().getThis();
        Class clazz = (Class) that.getExtra();

        String javaName = clazz.getJavaName();
        Object nameObj = StringPool.myString(clazz.getLoader(), javaName);

        frame.getOperandStack().pushRef(nameObj);
    }

}
